﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business.Entities;
using Business.Logic;

namespace UI.Desktop
{
    public partial class PlanesD : MdiFormPadre
    {

        private List<Especialidad> _ListaEspecialidad;

        public List<Especialidad> ListaEspecialidad
        {
            get { return _ListaEspecialidad; }
            set { _ListaEspecialidad = value; }
        }

        #region Constructores

        public PlanesD()
        {
            InitializeComponent();
            this.dgvPlanes.AutoGenerateColumns = false;
        }


        #endregion

        #region Métodos
        
        public void Listar()
        {
            try
            {
                PlanesLogic ml = new PlanesLogic();
                this.dgvPlanes.DataSource = null;
                this.dgvPlanes.DataSource = ml.GetAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        #endregion

        #region Eventos

        private void btnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tsbNuevo_Click(object sender, EventArgs e)
        {
            PlanesDesktop PlanesDesk = new PlanesDesktop(PlanesDesktop.ModoForm.Alta, ListaEspecialidad);
            PlanesDesk.ShowDialog();
            this.Listar();
        }

        private void tsbConsultar_Click(object sender, EventArgs e)
        {
            int i = ((Plan)this.dgvPlanes.SelectedRows[0].DataBoundItem).ID;
            PlanesDesktop PlanesDesk = new PlanesDesktop(i, UI.Desktop.PlanesDesktop.ModoForm.Consulta, ListaEspecialidad);
            PlanesDesk.ShowDialog();
            this.Listar();
        }

        private void tsbEditar_Click(object sender, EventArgs e)
        {
            int i = ((Plan)this.dgvPlanes.SelectedRows[0].DataBoundItem).ID;
            PlanesDesktop PlanesDesk = new PlanesDesktop(i, UI.Desktop.PlanesDesktop.ModoForm.Modifica, ListaEspecialidad);
            PlanesDesk.ShowDialog();
            this.Listar();
        }

        private void tsbEliminar_Click(object sender, EventArgs e)
        {
            int i = ((Plan)this.dgvPlanes.SelectedRows[0].DataBoundItem).ID;
            PlanesDesktop PlanesDesk = new PlanesDesktop(i, PlanesDesktop.ModoForm.Baja, ListaEspecialidad);
            PlanesDesk.ShowDialog();
            this.Listar();
        }

        private void PlanesD_Load(object sender, EventArgs e)
        {
            this.Listar();
            EspecialidadLogic Elogic = new EspecialidadLogic();
            ListaEspecialidad = Elogic.GetAll();
        }

        private void btnActualizar_Click(object sender, EventArgs e)
        {
            this.Listar();
        }

        #endregion

    }
}
